<template>
  <view class="index-wrapper">
    <view class="userinfo-itemlist">
      <view class="userinfo-item">
        <view class="item-left">
          <span style="padding-left: 0">切换租户</span>
        </view>
        <view class="item-right" @tap="goSettingSite">
          <span>{{ currentSite.name }}</span>
          <i class="iconfont">&#xe6bc;</i>
        </view>
      </view>
    </view>
    <view
      v-if="user && user.userId"
      class="userinfo-itemlist"
      style="padding-left: 0;"
    >
      <view
        class="userinfo-item"
        style="justify-content: center;"
        @tap="logOut"
      >退出登录</view>
    </view>
    <view v-else class="userinfo-itemlist" style="padding-left: 0;">
      <view
        class="userinfo-item"
        style="justify-content: center;"
        @tap="logIn"
      >登录</view>
    </view>
  </view>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "",
  components: {},
  props: {},
  data() {
    return {
      currentSite: null
    };
  },
  computed: {
    ...mapState(["site", "user"])
  },
  watch: {},
  created() {
    this.currentSite = this.site.currentSite;
  },
  mounted() {},
  methods: {
    goSettingSite() {
      uni.navigateTo({
        url: "/pages/setting/site"
      });
    },
    logOut() {
      this.$store.commit("site/clearSiteInfo");
      this.$store.commit("user/clearUserInfo");
      this.$store.commit("register/clearRegister");
      uni.navigateTo({
        url: "/authorize/index"
      });
    },
    logIn() {
      uni.navigateTo({
        url: "/authorize/index"
      });
    }
  }
};
</script>
